home *** CD-ROM | disk | FTP | other *** search
- /*
- DalisMaker.c
-
- Makes an 'alis' resource for each thing dropped on it and saves them in a new file
-
- NOTE: We assume at run-time that if Apple Events are available then the new System 7
- standard file package is also available. I know I shouldn't, but ╔
-
- Copyright ⌐ 1992 by Paul M. Hoffman
- Send feedback to paul.hoffman@um.cc.umich.edu
-
- This code may be freely used, altered, and distributed in any way you want as long as:
- 1. It is GIVEN away rather than sold;
- 2. This statement and the above copyright notice are left intact.
-
- Created 24 Apr 1992 v0.0 Some code
- Modified v0.1 Hey, it works! I hardly had to fix anything! Creates named
- 'alis' resources. Handles replaced files OK. I'm crossing
- my fingers on whether it'll make an alias for a volume ╔
- Yes! It makes an 'alis' resource for a floppy or hard disk that
- is identical to the one the Finder makes for it in an alias file
- ╤ not tested in a shared environment, however ╔
- 17 May 1992 v1.0b1 First release
-
- */
-
- #include "Dragon.h"
- #include <StandardFile.h>
- #include <Aliases.h>
-
- #define rAliasType 'alis'
- #define kLowNonSystemResID 128
-
- class DalisMaker: Dragon {
-
- public:
- virtual OSErr ProcessDroppings (FSSpec **docs, long numDocs);
-
- };
-
- OSErr DalisMaker::ProcessDroppings (FSSpec **docs, long numDocs)
- {
- StandardFileReply reply;
- OSErr err = noErr;
- short refNum, aliasResID;
- long i;
- AliasHandle aliasHndl;
- FSSpec *fss;
-
- StandardPutFile ("\pSave 'alis' resources in new file:", "\pAliases", &reply); // Pick a file to save aliases in
- if (reply.sfGood) {
- if (reply.sfReplacing)
- err = FSpDelete (&reply.sfFile);
- if (err == noErr) {
- FSpCreateResFile (&reply.sfFile, 'RSED', 'rsrc', reply.sfScript); // Create the file
- err = ResError ();
- if (err == noErr) {
- refNum = FSpOpenResFile (&reply.sfFile, fsCurPerm); // Open the file
- err = ResError ();
- if (err == noErr) {
- HLock ((Handle) docs);
- aliasResID = kLowNonSystemResID; // i.e., 128
-
- for (i = numDocs, fss = *docs; i--; fss++) { // Add each alias to the file
- NewAlias (NULL, fss, &aliasHndl);
- if (aliasHndl != NULL)
- AddResource ((Handle) aliasHndl, rAliasType, aliasResID++, &fss->name);
- }
-
- CloseResFile (refNum); // Close the file
- HUnlock ((Handle) docs);
- }
- }
- }
- }
-
- inherited::ProcessDroppings (docs, numDocs);
- }
-
- Dragon *CreateGDragon (void)
- {
- // If you want your dragon to do anything, you must override this method
- // so that it returns an instance of your dragon class ╤ forgetting to
- // change this method is an easy way to get totally frustrated!
-
- return (Dragon *) new DalisMaker;
- }